package buyticket;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:周次煜
 * Date: 2024-06-17
 * Time：11:02
 */



public class MyTicketSystem implements Runnable{
    static int count=10;
    @Override
    public synchronized void run() {

        for(int i=1;i<=5;i++) {
            count--;
            System.out.println(Thread.currentThread().getName()+"卖出一张票，还剩"+count+"张票");
        }
    }

}




 class Test {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        MyTicketSystem th1=new MyTicketSystem();
        Thread t1=new Thread(th1);
        Thread t2=new Thread(th1);
        t1.setName("窗口1");
        t2.setName("窗口2");
        t1.start();
        t2.start();
    }

}

